package studio.greeks.codes.region.tree;

import lombok.Data;
import lombok.experimental.Accessors;
import studio.greeks.codes.region.Region;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author dfs
 * @description studio.greeks.codes.region.tree normal-codes
 * @date 2021/5/7 00:17
 */
@Data
@Accessors(chain = true)
public class RegionNode{
    private RegionNode parent;
    private List<RegionNode> children;
    private Region region;

    public Region getRegion() {
        return region;
    }

    public void setRegion(Region region) {
        this.region = region;
    }

    public RegionNode parent() {
        return parent;
    }

    public List<RegionNode> children() {
        return children;
    }

    public List<RegionNode> brother() {
        if (isRoot()) {
            return null;
        }
        List<RegionNode> brother = new ArrayList<>(parent.children);
        brother.remove(this);
        return brother;
    }

    public boolean isRoot() {
        return parent == null;
    }

    public boolean isLeaf() {
        return children == null;
    }

    public String toString(){
        return region.toString();
    }
}
